package com.szqhyxj.youxiangju.biz.card.deposit;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.szqhyxj.youxiangju.BasePromptFragment;
import com.szqhyxj.youxiangju.R;
import com.szqhyxj.youxiangju.biz.card.CardModel;
import com.szqhyxj.youxiangju.sys.components.LoadImageUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 储蓄卡页面
 */
public class DepositFragment extends BasePromptFragment implements DepositContarct.View{

    @BindView(R.id.tubiao)
    ImageView tubiao;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.type)
    TextView type;
    @BindView(R.id.cardEnd)
    TextView cardEnd;

    Unbinder unbinder;
    @BindView(R.id.card_data)
    RelativeLayout cardData;
    private DepositPresenter depositPresenter;

    public static DepositFragment newInstance(){
        Bundle args = new Bundle();
        DepositFragment fragment = new DepositFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        depositPresenter = new DepositPresenter(this);
        depositPresenter.init();
    }

    @Override
    protected int getLayoutId(){
        return R.layout.fragment_deposit;
    }

    @Override
    protected void start(){
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView(){
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick(R.id.card_data)
    public void onViewClicked(View view){
        switch(view.getId()){
            case R.id.card_data:
                navCardDetails(depositPresenter.getCard());
                break;
        }
    }

    @Override
    public void showIcon(String url){
        LoadImageUtils.loadImage(tubiao, url);
    }

    @Override
    public void showName(String name){
        this.name.setText(name);
    }

    @Override
    public void showCardEnd(String code){
        int leng = code.length();
        this.cardEnd.setText(code.substring(leng-4));
    }

    @Override
    public void showCardData(int i){
        cardData.setVisibility(i);
    }

    @Override
    public void navCardDetails(CardModel.Card card){
        DepositDetailsActivity.start(getActivity(),card);
    }

    @Override
    public void showToast(String s) {

    }
}
